package Dao.Role.Imp;

        import Dao.Role.AllStudentDao;
        import Entity.Role.Student;
        import Util.DBUtil;

        import java.sql.Connection;
        import java.sql.PreparedStatement;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.util.ArrayList;
        import java.util.List;

public class AllStudentDaoImp implements AllStudentDao {
    private PreparedStatement ps = null;
    private ResultSet rs = null;

    @Override
    public List<Student> getAllStu(Connection conn) {
        List<Student> students = new ArrayList<>();
        try {
            String sql = "select sno,password,name,sex,tel,email,collname,classes,role,bh,major_name ,tno,email_code " +
                    "from stu_info";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                String sNO = rs.getString("sno");
                String password = rs.getString("password");
                String name = rs.getString("name");
                String sex = rs.getString("sex");
                String tel = rs.getString("tel");
                String email = rs.getString("email");
                String collName = rs.getString("collname");
                String classes = rs.getString("classes");
                String role = rs.getString("role");
                String bh = rs.getString("bh");
                String majorName = rs.getString("major_name");
                String tno = rs.getString("tno");
                String emailCode = rs.getString("email_code");
                Student student = new Student(sNO, password, name, sex, tel, email, collName, classes, role, bh, majorName,tno,emailCode);
                students.add(student);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.closeMySQLResource(ps, rs);
        }
        return students;
    }


}
